$(document).ready(function() {
	
	
	
});

function delete_project(project_id) {
	if(confirm('Are you sure you want to delete this project')) {
	
		$.post('/admin/projects_ajax/delete_project', { 'project_id' : project_id }, function(data) {
			if(data.deleted) {
				$('#project_wrapper_'+project_id).remove();
			}
		}, 'json');
		
	}
}

function open_media_manager(media) {
	create_overlay(null, function(sId, oImg, oParams) {
		create_popup('pages_media', 'pages_media_overlay', 760, 560, 'Select media', '/admin/media/popup/project_insert_'+media, function() {
			$(oImg).remove();
			$('#' + sId).remove();
			$('#pages_media_overlay').show();
		});
	}, {});
}

function project_insert_jpg(oObj, iMediaId, sDim) {
	sDim = 'thumbs';
	
	$.post('/admin/media_ajax/get_media_props', { iMediaId : iMediaId }, function(data) {
		
		if (data.extension_ext === 'jpg' || data.extension_ext === 'jpeg' || data.extension_ext === 'JPG' || data.extension_ext === 'JPEG') {
			var sSrc = '/assets/media/thumbs/' + data.media_subfolder + '/' + data.media_id + '.' + data.extension_ext;
			
			$('#project_jpg').val(data.media_id);
			
			$('#jpg_wrapper').html('<img src="'+sSrc+'" />');
			
			$('#pages_media_overlay').remove();
		} else {
			
			alert('Please select a jpg image.');
		
		}
	}, 'json');
}

function project_insert_pdf(oObj, iMediaId, sDim) {
	sDim = 'web';
	
	$.post('/admin/media_ajax/get_media_props', { iMediaId : iMediaId }, function(data) {
		
		if (data.extension_ext === 'pdf' || data.extension_ext === 'PDF') {
			var sSrc = '/assets/media/web/' + data.media_subfolder + '/' + data.media_id + '.' + data.extension_ext;
			
			$('#project_pdf').val(data.media_id);
			
			alert('The PDF has been added');
			
			$('#pages_media_overlay').remove();
		} else {
			
			alert('Please select a PDF.');
		
		}
	}, 'json');
}